#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2025/1/16 16:08
# @Author : ZhengQL

from playwright.sync_api import Page
import pytest

class LoginPage:

    def __init__(self, page:Page):
        self.page = page
        self.locator_username = page.get_by_placeholder("请输入用户名")
        self.locator_password = page.get_by_placeholder("请输入密码")
        self.locator_login_btn = page.get_by_role("button", name="立即登录")
        self.locator_regiter_btn = page.locator('text=没有账号？点这注册')

        # 账号输入框提示语
        self.locator_username_tip1 = page.locator(
            '[data-fv-validator="notEmpty"][data-fv-for="username"]'
        )
        self.locator_username_tip2 = page.locator(
            '[data-fv-validator="stringLength"][data-fv-for="username"]'
        )
        self.locator_username_tip3 = page.locator(
            '[data-fv-validator="regexp"][data-fv-for="username"]'
        )
        # 密码输入框提示语
        self.locator_password_tip1 = page.locator(
            '[data-fv-validator="notEmpty"][data-fv-for="password"]'
        )
        self.locator_password_tip2 = page.locator(
            '[data-fv-validator="stringLength"][data-fv-for="password"]'
        )
        self.locator_password_tip3 = page.locator(
            '[data-fv-validator="regexp"][data-fv-for="password"]'
        )
        # 账号或密码不正确！
        self.locator_register_error = page.locator('text=账号或密码不正确！')


    # 封装页面上的操作方法
    def navigate(self):
        self.page.goto('http://47.116.12.183/login.html')

    def fill_username(self, username):
        self.locator_username.fill(username)

    def fill_password(self, password):
        self.locator_password.fill(password)

    def click_login_btn(self):
        self.locator_login_btn.click()

    def click_register_btn(self):
        self.locator_regiter_btn.click()

    # 封装登录方法
    def login(self, username, password):
        self.locator_username.fill(username)
        self.locator_password.fill(password)
        self.locator_login_btn.click()





